from selenium import webdriver
import time


class Boom(object):
    def __init__(self):
        self.opt = webdriver.ChromeOptions()
        self.opt.add_argument('--headless')
        self.opt.add_argument('--no-sandbox')
        self.opt.add_argument('--disable-gpu')
        self.opt.add_argument('--disable-dev-shm-usage')
        self.opt.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"')
        self.driver = webdriver.Chrome(chrome_options=self.opt)
        self.phone_num = None

    def qq(self):
        url = 'https://ssl.zc.qq.com/v3/index-chs.html'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        nickname = self.driver.find_element_by_xpath('//input[@id="nickname"]')
        password = self.driver.find_element_by_xpath('//input[@id="password"]')
        phone = self.driver.find_element_by_xpath('//input[@id="phone"]')
        send_button = self.driver.find_element_by_xpath('//a[@id="send-sms"]')
        nickname.send_keys('mark')
        time.sleep(3)
        password.send_keys('12345678abc')
        time.sleep(3)
        phone.send_keys(self.phone_num)
        time.sleep(3)
        send_button.click()
        print('qq成功')

    def mi(self):
        url = 'https://cn.account.xiaomi.com/pass/register'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        phone = self.driver.find_element_by_xpath('//input[@name="phone"]')
        send_button = self.driver.find_element_by_xpath('//input[@type="submit"]')
        phone.send_keys(self.phone_num)
        time.sleep(3)
        send_button.click()
        print('小米成功')

    def guazi(self):
        url = 'https://www.guazi.com/www/bj/buy'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        login = self.driver.find_element_by_xpath('//a[@class="uc-my"]')
        login.click()
        time.sleep(2)
        phone = self.driver.find_element_by_xpath('//input[@name="phone"]')
        send_button = self.driver.find_element_by_xpath('//button[@class="get-code"]')
        phone.send_keys(self.phone_num)
        time.sleep(3)
        send_button.click()
        print('瓜子成功')

    def wphui(self):
        url = 'https://passport.vip.com/register'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        phone = self.driver.find_element_by_xpath('//input[@name="loginName"]')
        phone.send_keys(self.phone_num)
        time.sleep(3)
        send_button = self.driver.find_element_by_xpath('//a[@id="J_mobile_verifycode_btn"]')
        send_button.click()
        print('唯品会成功')

    def suning(self):
        url = 'https://reg.suning.com/company.do'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        # agree = self.driver.find_element_by_xpath('//a[@class="agree-btn"]')
        # agree.click()
        # time.sleep(3)
        phone = self.driver.find_element_by_xpath('//input[@id="cntctMobileNum"]')
        send_button = self.driver.find_element_by_xpath('//a[@id="sendSmsCode"]')
        phone.send_keys(self.phone_num)
        send_button.click()
        print('苏宁成功')

    def yhd(self):
        url = 'https://passport.yhd.com/passport/register_input.do'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        phone = self.driver.find_element_by_xpath('//input[@id="phone"]')
        phone.send_keys(self.phone_num)
        time.sleep(2)
        send_button = self.driver.find_element_by_xpath('//a[@class="receive_code fl same_code_btn r_require_code"]')
        send_button.click()
        print('一号店成功')

    def youzan(self):
        url = 'https://www.youzan.com/v2/account'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        phone = self.driver.find_element_by_xpath('//input[@name="mobile"]')
        phone.send_keys(self.phone_num)
        time.sleep(2)
        send_button = self.driver.find_element_by_xpath('//button[@class="btn js-fetch-sms btn-operation"]')
        send_button.click()
        print('有赞成功')

    def pindd(self):
        url = 'http://mobile.yangkeduo.com/login.html'
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        login = self.driver.find_element_by_xpath('//div[@class="phone-login"]')
        login.click()
        time.sleep(2)
        phone = self.driver.find_element_by_xpath('//input[@id="user-mobile"]')
        phone.send_keys(self.phone_num)
        send_button = self.driver.find_element_by_xpath('//button[@id="code-button"]')
        send_button.click()
        print('拼多多成功')

    def run(self):
        self.qq()
        self.guazi()
        self.mi()
        self.wphui()
        self.suning()
        # self.yhd()  # 失败率较高
        self.youzan()
        self.pindd()


if __name__ == '__main__':
    boom = Boom()
    boom.phone_num = input('请输入手机号=')
    boom.run()
